#{extends 'admin.html' /}
#{set title:'Administration : Edition d\'un Article' /}
#{if flash.error}
<h4 class="alert_error">${flash.error}</h4>
#{/if}
<article class="module width_full">
    <header>
        <h3 class="tabs_involved">Edition de l'article: ${entity.formatTitle(44)}</h3>
        <ul class="tabs">
            <li><a href="@{Articles.list}">Annuler</a></li>
        </ul>
    </header>

    <div class="entity">
        #{form @Articles.update(), id:'editArticleForm', enctype:'multipart/form-data'}
        <div class="module_content">
            <fieldset>
                <label>Titre : </label>
                <input type="text" name="entity.title" value="${entity?.title}"/>
                <span class="error">${errors.forKey('entity.title')}</span>
            </fieldset>
            <fieldset>
                <label>Catégorie : </label>
                <select name="entity.category.id">
                    %{ models.Category.all().fetch().sort{ it.toString() }.each() { }%

                    %{
                    selected = false;
                    if (entity?.category?.id == it.id) {
                    selected = true
                    }
                    }%
                    <option value="${it?.id}" ${selected ? 'selected'.raw() : ''}>${it}</option>
                    %{ } }%
                </select>
                <span class="error">${errors.forKey('entity.category')}</span>
            </fieldset>
            <fieldset>
                <label>Image associée : </label>
                    <input type="file" name="imgArticle"/><span>&nbsp;Facultatif</span>
                <span class="error">${errors.forKey('imgArticle')}</span>
            </fieldset>
            <fieldset>
                <label>Corps : </label>
                <textarea name="entity.content">${entity?.content}</textarea>
                <span class="error">${errors.forKey('entity.content')}</span>
            </fieldset>
            <input type="hidden" name="entity.id" value="${entity?.id}"/>
        </div>
        <footer>
            <div class="submit_link">
                <input type="submit" name="submit" value="Modifier !" class="alt_btn"/>
            </div>
        </footer>
    </div>
    #{/form}
</article>
